package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.common.constant.MessageConstant;
import com.atguigu.common.entity.Result;
import com.atguigu.common.utils.POIUtils;
import com.atguigu.service.OrderSettingService;
import com.atguigu.vo.EditNumberByDateVo;
import com.atguigu.vo.OrderSettingDateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/ordersetting")
public class OrderSettingController {
    @Reference
    OrderSettingService orderSettingService;

    //上传文件
    @PostMapping("/upload")
    public Result uploadFile(@RequestParam("excelFile")MultipartFile file){
        try {
            //2010-10 100
            List<String[]> strings = POIUtils.readExcel(file);
            orderSettingService.addExcel(strings);

        } catch (IOException e) {

            return new Result(false, MessageConstant.UPLOAD_SUCCESS);
        }
        return new Result(true,MessageConstant.UPLOAD_SUCCESS);
    }


    //修改预约人数
    @PostMapping("/editNumberByDate")
    public Result editNumberByDate(@RequestBody EditNumberByDateVo dateVo){
        orderSettingService.update(dateVo.getOrderDate(),dateVo.getNumber());
        return new Result(true,MessageConstant.ORDERSETTING_SUCCESS);
    }


    @GetMapping("/getOrderSettingByMonth")
    public Result getOrderSettingByMonth(@RequestParam("date")String date){
        List<OrderSettingDateVo> orderSettings = orderSettingService.selectDate(date);
        return new Result(true,MessageConstant.QUERY_ORDER_SUCCESS,orderSettings);
    }

}
